<?php

/**
 * page home de la galerie video
 * 
 * @author Toky RABESON <t.rabeson@medias-solution.com>
 * @todo traitement des erreurs
 */


$page['L_message'] = "" ;
if (!$right_user['videocat_list'] || !$right_user['video_list']) 
{
    // redirection vers page d'erreur de droit
    // header('location:') ;
}

$zSql     = " SELECT * FROM pms_plug_videocat WHERE videocat_status = 1" ;
$oConnect = sql_connect();
$oResult  = sql_query($zSql) ;
$page['toCatVideos'] = array() ;
$iKey       = 0 ;

while ($toItems = sql_fetch_array($oResult)) 
{
    $toConds['condition'] = " WHERE video_catid = " . $toItems['videocat_id'] . " AND video_status = 1 " ;
    $toConds['order']     = " ORDER BY video_id DESC " ;
    $toConds['limit']     = " LIMIT 1 " ;
    $zSql                 = sql_replace($sql['video']['select_video_condition'], $toConds);
    $oResVideo            = sql_query($zSql) ;
    $toItems['toVideos']  = sql_fetch_array($oResVideo) ;
    if ($toItems['toVideos'])
    {
        // $iKey                              = $toItems['videocat_id'] ;
        $page['toCatVideos'][$iKey]['id']          = $toItems['videocat_id'] ;
        $page['toCatVideos'][$iKey]['name']        = $toItems['videocat_name'] ;
        $page['toCatVideos'][$iKey]['description'] = $toItems['videocat_description'] ;
        $page['toCatVideos'][$iKey]['videoId']     = $toItems['toVideos']['video_id'] ;
        $page['toCatVideos'][$iKey]['videoName']   = $toItems['toVideos']['video_name'] ;
        $page['toCatVideos'][$iKey]['videoUrl']    = $toItems['toVideos']['video_url'] ;
        $toUrlVideos = getVideo ($toItems['toVideos']['video_url']) ;
        if ($toUrlVideos)
        {
            $page['toCatVideos'][$iKey]['url_thumb'] = $toUrlVideos['thumb'] ;
            $page['toCatVideos'][$iKey]['url_video'] = $toUrlVideos['embed'] ;
        }
        else
        {
            $page['toCatVideos'][$iKey]['url_thumb'] = '' ;
            $page['toCatVideos'][$iKey]['url_video'] = '' ;
        }
        
        $iKey++ ;
    }
}

sql_close($oConnect);

# meta
$page['meta_title']=$lang['video']['video_list'];
$page['template']=$tpl['video']['video_home'];

